package com.hitqz.robot.driver.dto;

import com.hitqz.robot.driver.model.IRobotPosDto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.math.RoundingMode;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class KcRobotRunningStatus {
    private double bodyTemperature ;//本体温度
    private double positionX ;//x坐标
    private double positionY ;//y坐标
    private double orientationAngle ;//转向
    private double batteryPower;//电量 0~1
    private int isBlocked ;//是否被阻挡 0-否 其他-是
    private int isCharging;//是否在充电 0-否 1-是
    private int runMode;//运行模式 0-手动 1-自动
    private int mapLoadStatus;//地图载入状态 0-成功 1-失败 2-未载入 3-正在载入
    private int targetPointId;//目标点id
    private double forwardSpeed;//前进速度
    private double turnSpeed;//转弯速度
    private double batteryVoltage;//电池电压，正充电，负放电
    private double current;//电池电流，正充电，负放电
    private int taskStatus;//当前任务状态 0-无前往导航点的任务 1-等待 2-正在前往导航点 3-暂停 4-完成 5-失败 6-退出 7-等待开/关门
    private int reserved1; //保留位1
    private int mapVersion; //地图版本号
    private byte[] reserved2; // 保留位2
    private double totalMileage; //累计里程 m
    private double currentRunTime; //本次运行时间 ms
    private double totalRunTime;//累计运行时间 ms
    private int robotPositionStatus;//定位状态 0-失败 1-成功 2-定位中 3-定位完成
    private byte[] reserved3;//保留位3
    private int mapCount;//地图数量
    private String currentMapName;//当前地图名称
    private float confidence;//置信度0~1
    private byte[] reserved4;//保留位4


    private int onlineStatus;//因为是udp,要自己轮询，加个在线状态去做通讯判断 0-离线 1-在线

    //离线状态默认值
    public static KcRobotRunningStatus getDefault(){
        return new KcRobotRunningStatus();
    }

    public static IRobotPosDto getIRobotPosDto(KcRobotRunningStatus runningStatus){
        IRobotPosDto dto = new IRobotPosDto();
        dto.setControllerTemp(Double.valueOf(runningStatus.getBodyTemperature()).floatValue());
        dto.setX(Double.valueOf(runningStatus.getPositionX()).floatValue());
        dto.setY(Double.valueOf(runningStatus.getPositionY()).floatValue());
        dto.setAngle(Double.valueOf(runningStatus.getOrientationAngle()).floatValue());
        dto.setCurrentStation("");
        dto.setVx(Double.valueOf(runningStatus.getForwardSpeed()).floatValue());
        dto.setVy(Double.valueOf(runningStatus.getTurnSpeed()).floatValue());
        dto.setW(0.0F);
        dto.setBlocked(runningStatus.getIsBlocked() != 0);
        dto.setBatteryLevel(BigDecimal.valueOf(runningStatus.getBatteryPower()).multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP).floatValue());
        dto.setCharging(runningStatus.getIsCharging() != 0);
        dto.setEmergency(false);// todo
        dto.setCurrentMap(runningStatus.getCurrentMapName());
        dto.setCreateOn("");
        dto.setBrake(false);
        dto.setSoftEmc(false);
        dto.setTaskStatus(runningStatus.getTaskStatus());
        dto.setBlockReason("");
        dto.setVoltage(Double.valueOf(runningStatus.getBatteryVoltage()).floatValue());
        dto.setCurrent(String.format("%.2f", runningStatus.getCurrent()));
        dto.setSpeed(BigDecimal.valueOf(runningStatus.getForwardSpeed()).setScale(2, RoundingMode.HALF_UP).doubleValue());
        return dto;
    }

}
